package io.gitee.twoke.generator.engine.impl.cmd;

import io.gitee.twoke.generator.engine.impl.generate.DataTableColumn;
import io.gitee.twoke.generator.engine.impl.interceptor.Command;
import io.gitee.twoke.generator.engine.impl.interceptor.CommandContext;
import io.gitee.twoke.generator.engine.impl.persistence.entity.DataTableColumnEntity;

import java.util.Objects;

public class UpdateColumnCmd implements Command<Void> {

    private DataTableColumnEntity column;

    public UpdateColumnCmd(DataTableColumn column) {
        if (Objects.isNull(column) || Objects.isNull(column.getId())) {
            throw new IllegalArgumentException("column is null");
        }
        if (!DataTableColumnEntity.class.isAssignableFrom(column.getClass())) {
            throw new IllegalArgumentException("column is not instance of " + DataTableColumnEntity.class.getName());
        }
        this.column = (DataTableColumnEntity)column;
    }

    @Override
    public Void execute(CommandContext commandContext) {
        commandContext.getDataTableColumnEntityManager().update(this.column);
        return null;
    }
}
